//
//  LoginView.m
//  豆瓣
//
//  Created by dllo on 15/12/7.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "LoginView.h"

@implementation LoginView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (void)dealloc{
    [_usernameLabel release];
    [_usernameText release];
    [_passwordLabel release];
    [_passwordText release];
    
    [super dealloc];
    
}
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubviews];
    }
    return self;
}

- (void)createSubviews{
    self.usernameLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, 90, 100, 50)];
    self.usernameLabel.text = @"用户名:";
    [self addSubview:_usernameLabel];
    [_usernameLabel release];
    
    self.passwordLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, 160, 100, 50)];
    self.passwordLabel.text = @"密码:";
    [self addSubview:_passwordLabel];
    [_passwordLabel release];
    
    
    self.usernameText = [[UITextField alloc] initWithFrame:CGRectMake(120, 90, 200, 40)];
    self.usernameText.placeholder = @"请输入用户名";
    self.usernameText.borderStyle = UITextBorderStyleRoundedRect;
//    self.usernameText.layer.cornerRadius = 10;
    [self addSubview:_usernameText];
    [_usernameText release];
    
    self.passwordText = [[UITextField alloc] initWithFrame:CGRectMake(120, 160, 200, 40)];
    self.passwordText.placeholder = @"请输入密码";
    self.passwordText.borderStyle = UITextBorderStyleRoundedRect;
    [self addSubview:_passwordText];
    [_passwordText release];
    
    
    UIButton *loginButton = [UIButton buttonWithType:UIButtonTypeCustom];
    loginButton.frame = CGRectMake(40, 240, 145, 46);
//    loginButton.backgroundColor = [UIColor colorWithRed:154/255.0 green:194/255.0 blue:73/255.0 alpha:1];
    [loginButton setImage:[UIImage imageNamed:@"login_button"] forState:UIControlStateNormal];
    [loginButton addTarget:self action:@selector(loginButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [self addSubview:loginButton];
    
    UIButton *registerButton = [UIButton buttonWithType:UIButtonTypeCustom];
    registerButton.frame = CGRectMake(200, 240, 145, 46);
//    registerButton.backgroundColor = [UIColor blackColor];
    [registerButton setImage:[UIImage imageNamed:@"register_button"] forState:UIControlStateNormal];

    [self addSubview:registerButton];
    [registerButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    
}

- (void)loginButtonAction:(UIButton *)button{
    
    [self.myDelegate loginAlert];
}

- (void)buttonAction:(UIButton *)button{
//    NSLog(@"______");
    
    [self.myDelegate pushToRegisterView];
    
}



@end
